package com.scau.dao.Impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.session.SqlSession;
import org.springframework.stereotype.Repository;

import com.scau.dao.TeacherDao;
import com.scau.mapper.TeacherMapper;
import com.scau.pojo.Student;
import com.scau.pojo.Teacher;
import com.scau.util.SqlSessionFactoryUtil;

@Repository
public class TeacherDaoImpl implements TeacherDao{
	
	SqlSession session = SqlSessionFactoryUtil.getSession();
	TeacherMapper teacherMapper=session.getMapper(TeacherMapper.class);
	@Override
	public List<Teacher> query() {
		return teacherMapper.selectByExample(null);
	}
	@Override
	public int add(Teacher teacher) {
		return teacherMapper.insertSelective(teacher);
	}
	@Override
	public int deleteMulti(int id) {
		return teacherMapper.deleteByPrimaryKey(id);
	}
	@Override
	public int update(Teacher teacher) {
		return teacherMapper.updateByPrimaryKeySelective(teacher);
	}
	@Override
	public Map<String, Object> getTeacherByName(String tName) {
		Map<String,Object> map=new HashMap<String,Object>();
		try {
			Teacher teacher=teacherMapper.selectByName(tName);
			if(teacher==null){
				map.put("returnCode", -1);
				map.put("teacher", null);
			}else{
				map.put("returnCode", 1);
				map.put("teacher", teacher);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return map;
	}
	@Override
	public int isExist(String tName) {
		int result=-1;
		Teacher teacher=new Teacher();
		try {
			teacher=teacherMapper.selectByName(tName);
			if(teacher!=null){
				result=1;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}
	
}
